﻿/*****************************************************************************
	SNEGA STG GAME ENGINE 0.7a
	Copyright (C) 2009, Xiaohan Tian (snega0223)
	
	http://code.google.com/p/sng-actionscript-stg-engine/
	
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License(LGPL) as
	published by the Free Software Foundation, either version 3 of the 
	License, or(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

package com.sng.stg.game.event 
{
	import com.sng.stg.game.StageViewer;
	import flash.display.Bitmap;
	
	/**
	 * ...
	 * @author snega
	 */
	public class DisplayMask2D extends ContinuousEvent
	{
		protected var _bitmap:Bitmap = null;
		
		protected var _status:int = 0;
		protected var _frame:int = 0;
		
		public function DisplayMask2D(bitmap:Bitmap) 
		{
			this._bitmap = bitmap;
		}
		
		override public function start(stage:StageViewer):void {
			this._stage = stage;
		}
		
		override public function process():void {
			switch (this._status) {
				case 0: {
					this._stage._2dMask.addChild(this._bitmap);
					this._bitmap.alpha = 0.4;
					this._status = 1;
					break;
				}
				case 1: {
					this._bitmap.alpha += 0.01;
					if (this._bitmap.alpha == 1) {
						this._status = 2;
					}
					break;
				}
				case 2: {
					if (++this._frame == 120) {
						this._status = 3;
					}
					break;
				}
				case 3: {
					this._bitmap.alpha -= 0.01;
					if (this._bitmap.alpha == 0.4) {
						this._status = 4;
					}
					break;
				}
				case 4: {
					this._stage._2dMask.removeChild(this._bitmap);
					this.remove();
					break;
				}
			}
		}
		
	}
	
}